﻿@using Digital.WCFClient.ConfigService
@using System.Collections.ObjectModel
@using Digital.Common.Mvc.Extensions
@using Digital.Web.Controllers
@using Microsoft.AspNet.Identity
@using Digital.Common.Utilities
@model Digital.WCFClient.ConfigService.PatentModel
@{
    ViewBag.Title = "添加专利";
    Layout = "~/Views/Shared/_LayoutDigital.cshtml";
}
@section PageSpecificJavascriptIncludes{

    @*<link rel="stylesheet" href="../DigitalStyle/css/jquery.gritter.css" />
            <link rel="stylesheet" href="../DigitalStyle/css/bootstrap-fileupload.min.css" />
            <link rel="stylesheet" href="../DigitalStyle/css/jquery.tagsinput.css" />

            <script src="../DigitalStyle/js/jquery.gritter.min.js"></script>
            <script src="../DigitalStyle/js/jquery.validate.min.js"></script>
            <script src="../DigitalStyle/js/JqueryToken.js"></script>
            <script src="../DigitalStyle/js/jquery.autogrow-textarea.js"></script>
            <script src="../DigitalStyle/js/messages_cn.js"></script>
            <!-- CKEditor -->
            <script src="../DigitalStyle/js/ckeditor/ckeditor.js"></script>
            <script src="../DigitalStyle/js/ckeditor/adapters/jquery.js"></script>
            <!-- commom form js -->
            <script src="../DigitalStyle/js/jquery.tagsinput.min.js"></script>
        <script type="text/javascript" src="@Url.StaticFile("/DigitalStyle/js/flashupload.js")"></script>*@
    <link rel="stylesheet" href="../DigitalStyle/css/jquery.gritter.css" />
    <link rel="stylesheet" href="../DigitalStyle/css/bootstrap-fileupload.min.css" />
    <link rel="stylesheet" href="../DigitalStyle/css/jquery.tagsinput.css" />

    <script src="../DigitalStyle/js/jquery.autogrow-textarea.js"></script>
    <script src="../DigitalStyle/js/bootstrap-fileupload.min.js"></script>
    <script src="../DigitalStyle/js/jquery.maskedinput.min.js"></script>
    <script src="../DigitalStyle/js/jquery.tagsinput.min.js"></script>

    <script src="../DigitalStyle/js/jquery.gritter.min.js"></script>
    <script src="../DigitalStyle/js/jquery.validate.js"></script>
    <script src="../DigitalStyle/js/JqueryToken.js"></script>
    <script src="../DigitalStyle/js/messages_cn.js"></script>


    <!-- CKEditor -->
    <script src="../DigitalStyle/js/ckeditor/ckeditor.js"></script>
    <script src="../DigitalStyle/js/ckeditor/adapters/jquery.js"></script>
    <script type="text/javascript" src="@Url.StaticFile("/DigitalStyle/js/flashupload.js")"></script>
    <script src="../DigitalStyle/js/formvalidator.js"></script>

}
<div class="pageheader">
    <h2><i class="fa fa-user"></i> 添加专利 <span>专利中心</span></h2>
    <div class="breadcrumb-wrapper">
        <span class="label">你的位置:</span>
        <ol class="breadcrumb">
            <li><a href="">企业中心</a></li>
            <li class="active">专利中心</li>
        </ol>
    </div>
</div>

<div class="contentpanel">
    <div class="row">

        <div class="col-sm-12">
            <div class="panel panel-info">
                <div class="panel-heading">
                    <div class="panel-btns">
                        <a href="" class="panel-close">&times;</a>
                        <a href="" class="minimize">&minus;</a>
                    </div><!-- panel-btns -->
                    <h3 class="panel-title">专利管理</h3>
                </div>


                <div class="panel-body panel-body-nopadding">
                    <form class="form-horizontal form-bordered" id="firstForm" onsubmit="return false">
                        @Html.AntiForgeryToken()
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 专利号</label>
                            <div class="col-sm-6">
                                @*<input id="PatentNumber" value="@Model.PatentNumber" type="text" placeholder="专利号" class="form-control"  />*@
                                @Html.TextBoxFor(m => m.PatentNumber, new { @class = "form-control", @placeholder = "专利号" })
                                @Html.ValidationMessageFor(m => m.PatentNumber, null, new { @class="help-inline"})
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 专利名称</label>
                            <div class="col-sm-6">
                                @*<input id="PatentName" value="@Model.PatentName" type="text" placeholder="专利名称" class="form-control"  />*@
                                @Html.TextBoxFor(m => m.PatentName, new { @class = "form-control", @placeholder = "专利名称" })
                                @Html.ValidationMessageFor(m => m.PatentName, null, new { @class="help-inline"})
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 专利概述</label>
                            <div class="col-sm-6">
                                @*<textarea id="PatentAbstract" class="form-control" rows="5">@Model.PatentAbstract</textarea>*@
                                @Html.TextAreaFor(m => m.PatentAbstract, new { @class = "form-control",@rows="5" })
                                @Html.ValidationMessageFor(m => m.PatentAbstract, null, new { @class="help-inline"})
                                <span class="help-block">
                                    (限制100字以内)
                                </span>
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 专利证书</label>
                            <div class="col-sm-6">
                                <div class="fileupload fileupload-new" data-provides="fileupload" id="container">
                                    <div class="input-append">
                                        <div class="uneditable-input">
                                            <i class="glyphicon glyphicon-file fileupload-exists"></i>
                                            <span id="filelist" class="fileupload-preview"></span>
                                        </div>
                                        <span class="btn btn-default btn-file">
                                            <span class="fileupload-new">选择专利证书文件</span>
                                            <span class="fileupload-exists">更改</span>
                                            @*<input id="pickfiles" value="@Model.PatentCerificate" type="file" />*@
                                            @Html.TextBoxFor(m => m.PatentCerificate, new { @id = "pickfiles", @type = "file" })
                                            @Html.ValidationMessageFor(m => m.PatentCerificate, null, new { @class="help-inline"})
                                        </span>
                                        <a href="#" id="uploadfiles" class="btn btn-default">上传</a>
                                    </div>
                                </div>
                                <input id="ImagePath" type="hidden" value="@Model.PatentCerificate" />

                                <img id="PersonImage" src="@Html.IsNull(Model.PatentCerificate, "../DigitalStyle/images/pic-none.png", Model.PatentCerificate)" class="thumbnail img-responsive" alt="" />
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 专利日期</label>
                            <div class="col-sm-4 ">
                                <div class="input-group">
                                    @*<input id="PatentDate" value="@Model.PatentDate" type="text" class="form-control" placeholder="mm/dd/yyyy" required />*@
                                    @Html.TextBoxFor(m => m.PatentDate, new { @class = "form-control", @placeholder = "mm/dd/yyyy" })
                                    @Html.ValidationMessageFor(m => m.PatentDate, null, new { @class="help-inline"})
                                    <span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">技术领域</label>

                            <div class="col-sm-4 ">
                                <select id="TechnologyDomain" class="form-control chosen-select" data-placeholder="选择分类..." required>
                                    <option value="0"> --请选择-- </option>
                                </select>
                            </div>

                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">开发状态</label>

                            <div class="col-sm-4 ">
                                <select id="DevelopmentStatus" class="form-control chosen-select" data-placeholder="选择状态..." required>
                                    <option value="0"> --请选择-- </option>
                                </select>
                            </div>

                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">排序值</label>
                            <div class="col-sm-4">
                                @*<input id="PatentOrderID" value="@Model.PatentOrderID" type="text" placeholder="50" class="form-control" />*@
                                @Html.TextBoxFor(m => m.PatentOrderID, new { @class = "form-control", @placeholder = "50" })
                                @Html.ValidationMessageFor(m => m.PatentOrderID, null, new { @class="help-inline"})
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label"><span class="asterisk">*</span> 标签</label>
                            <div class="col-sm-4">
                                @*<input id="PatentLabels" name="PatentLabels" class="form-control" value="@Model.PatentLabels" />*@
                                @Html.TextBoxFor(m => m.PatentLabels, new { @class = "form-control" })
                                @Html.ValidationMessageFor(m => m.PatentLabels, null, new { @class="help-inline"})
                            </div>
                        </div>



                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="checkbox"><span class="asterisk">*</span> 专利简介</label>
                            <div class="col-sm-6">
                                @*<textarea id="PatentIntro" name="PatentIntro" placeholder="请在此输入专利简介" class="form-control" rows="10" required>@Model.PatentIntro</textarea>*@
                                @Html.TextAreaFor(m => m.PatentIntro, new { @class = "form-control", @placeholder = "请在此输入专利简介", @rows = "10" })
                                @Html.ValidationMessageFor(m => m.PatentIntro, null, new { @class="help-inline"})
                                <span class="help-block">
                                    (限制500字以内)
                                </span>
                            </div>
                        </div>

                        <div class="panel-footer">
                            <div class="row">
                                <div class="col-sm-6 col-sm-offset-3">
                                    <button class="btn btn-primary" onclick="javascript: Save();">提交</button>&nbsp;
                                    <button class="btn btn-default">取消</button>
                                </div>
                            </div>
                        </div>

                    </form>
                </div>

            </div><!-- panel -->
        </div>
    </div>
</div>
<script>
    function callback(msg)
    {
        $("#ImagePath").val(msg.msg.url);
        $("#PersonImage")[0].src = msg.msg.url;
    }
    jQuery(document).ready(function () {
        $('#UploadButton').FileUpload({
            'subfolder': 'UserInfo' + '@Digital.Common.CryptoService.MD5Encrypt(User.Identity.GetUserId(),Digital.Common.SerurityType.UserInfoFolder)',
            'ImageId': '',
        });

        //select option : TechnologyDomain
        var TechnologyDomainjsons=@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject((ObservableCollection<TechnologyDomainMode>)ViewBag.TechnologyDomainList))
        DropOption(TechnologyDomainjsons,$("#TechnologyDomain"),@Model.PatentTechnologyDomain);
        //select option : DevelopmentStatus
        var DevelopmentStatusjsons=@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject((ObservableCollection<DevelopmentStatusMode>)ViewBag.DevelopmentStatusList))
        DropOption(DevelopmentStatusjsons,$("#DevelopmentStatus"),@Model.PatentDevelopmentStatus);

        // Chosen Select
        jQuery(".chosen-select").chosen({ 'width': '100%', 'white-space': 'nowrap' });

        // Tags Input
        jQuery('#PatentLabels').tagsInput({ width: 'auto' });

        // Textarea Autogrow
        jQuery('#PatentAbstract').autogrow();

        // Date Picker
        jQuery('#datepicker').datepicker();
        jQuery('#datepicker-inline').datepicker();
        jQuery('#datepicker-multiple').datepicker({
            numberOfMonths: 3,
            showButtonPanel: true
        });

        // CKEditor
        jQuery('textarea#PatentIntro').ckeditor();
        CKEDITOR.instances["PatentIntro"].on("instanceReady", function()   
        {   
            //set keyup event   
            this.document.on("keyup", updateTextArea);   
            //and paste event   
            this.document.on("paste", updateTextArea);   
  
        });

        // With Form Validation Wizard
        jQuery("#firstForm").validate({
            rules:{
                PatentNumber:{
                    required:true,
                    isContainsSpecialChar:true
                },
                PatentName:{
                    required:true,
                    isContainsSpecialChar:true
                },
                PatentAbstract:{
                    required:true,
                    stringContentCheck:[1,200]
                },
                PatentCerificate:{
                    required:true
                },
                PatentDate:{
                    required:true
                },
                PatentLabels:{
                    required:true
                },
                PatentIntro:{
                    required:true,
                    stringContentCheck:[1,1000]
                }
            },
            messages:{
                PatentNumber:{
                    required:"请输入专利号",
                    isContainsSpecialChar:"含有中英文特殊字符"
                },
                PatentName:{
                    required:"请输入专利名称",
                    isContainsSpecialChar:"含有中英文特殊字符"
                },
                PatentAbstract:{
                    required:"请输入专利概述",
                    stringContentCheck:$.validator.format("请确保内容输入{0}-{1}字节以内")
                },
                PatentCerificate:{
                    required:"请选择专利缩略图"
                },
                PatentDate:{
                    required:"请选择专利日期"
                },
                PatentLabels:{
                    required:"请输入专利标签",
                    isContainsSpecialChar:"含有中英文特殊字符"
                },
                PatentIntro:{
                    required:"请输入专利内容",
                    stringContentCheck:$.validator.format("请确保内容输入{0}-{1}字节以内")
                }
            },
            highlight: function (element) {
                jQuery(element).closest('.form-group').removeClass('has-success').addClass('has-error');
            },
            success: function (element) {
                jQuery(element).closest('.form-group').removeClass('has-error');
            },
            focusInvalid: false,
            onkeyup: false,
            ignore:'',
            errorPlacement: function (error, element) {
                //alert(error.html());
                error.insertAfter($(element).parent().children().last());
            }
        });

    });
</script>
<script>

    function updateTextArea()   
    {   
        CKEDITOR.tools.setTimeout( function()   
        {    
            $("#PatentIntro").val(CKEDITOR.instances[$("#PatentIntro").attr("id")].getData());   
            $("#PatentIntro").trigger('keyup');  
            $("#PatentIntro").trigger('paste');
        }, 0);     
    } 
    // For Patent Add Operation , Submit Button
    function Save() {
        var $valid = jQuery('#firstForm').valid();
        //debugger;
        if (!$valid) {
            return false;
        }
        else {
            @{
                 var Ids = Request["Id"] == null ? "0" : Request["Id"].ToString();
             }
            var IsInsert=@Ids;
            var PatentID = 0; // default option : insert patent model

            //------------------TAB 01 : 专利信息
            var valPatentNumber = $.jsparams.input("PatentNumber");
            var valPatentName = $.jsparams.input("PatentName");
            var valPatentAbstract = $.jsparams.input("PatentAbstract");
            var valPatentDate = $.jsparams.input("PatentDate");
            var valPatentTechnologyDomain = $.jsparams.select("TechnologyDomain");
            var valPatentDevelopmentStatus = $.jsparams.select("DevelopmentStatus");
            var valPatentOrderID = $.jsparams.input("PatentOrderID");
            var valPatentLabels = $.jsparams.input("PatentLabels");
            var valPatentIntro = $.jsparams.textarea("PatentIntro");
            var Image = $.jsparams.input("ImagePath");


            var datas= {Id:IsInsert,PatentNumber:valPatentNumber,PatentName:valPatentName,
                PatentAbstract:valPatentAbstract,PatentCerificate:Image,PatentDate:valPatentDate,
                PatentTechnologyDomain:valPatentTechnologyDomain,PatentDevelopmentStatus:valPatentDevelopmentStatus,
                PatentOrderID:valPatentOrderID,PatentLabels:valPatentLabels,PatentIntro:valPatentIntro,ImageSrc:Image};
            ComAjax("/Company/CompanyPatentSave",datas,"专利信息");

        }
    }

</script>



